package top.huhuiyu.spirngboot2.total.scheduling;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.huhuiyu.spirngboot2.total.dao.UtilsDAO;
import top.huhuiyu.spirngboot2.total.service.AuthService;
import top.huhuiyu.spirngboot2.total.service.AutoDataService;

@Slf4j
@Component
@EnableScheduling
@RequiredArgsConstructor
public class AutoTask {
    private final UtilsDAO utilsDAO;
    private final AutoDataService autoDataService;

    /**
     * 计划任务测试的日志
     */
    @Scheduled(fixedDelay = 5 * 60 * 1000, initialDelay = 60 * 1000)
    public void log() {
        log.debug("计划任务执行：{}", utilsDAO.queryNowTimestamp());
    }

    @Scheduled(fixedDelay = 5 * 60 * 1000, initialDelay = 2 * 60 * 1000)
    public void user() {
        try {
            int result = autoDataService.makeUser();
            log.debug("自动注册用户数{}", result);
        } catch (Exception ex) {
            log.debug("计划任务执行异常：{}", ex.getMessage());
        }
    }


}
